#include <iostream>
using namespace std;

const int N = 1010;
int n, m;
int v[N], w[N];
int f[N];

int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
        cin >> v[i] >> w[i];
    // 二维优化
    // f[i][j] = max(f[i-1][j], f[i-1][j-v]+w, f[i-1][j-2v]+2w,...,f[i-1][j-nv]+nw)
    // f[i][j-v]=max(           f[i-1][j-v],   f[i-1][j-2v]+w,....,f[i-1][j-nv]+(n-1)w)
    // f[i][j] = max(f[i-1][j], f[i][j-v])
    /*for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= m; ++j)
        {
            f[i][j] = f[i - 1][j];
            if(j >= v[i]) f[i][j] = max(f[i][j], f[i][j - v[i]] + w[i]);
        }*/
    // 一维优化
    for (int i = 1; i <= n; ++i)
        for (int j = v[i]; j <= m; ++j)
            f[j] = max(f[j], f[j - v[i]] + w[i]);
    cout << f[m] << endl;
    return 0;
}
